#include <stdio.h>
#include <string.h>
int main ()
{
	int n,i;
	scanf("%d",&n);
	struct StudentType 
	{
		char name[21];
		int sno;
		double chinese;
		double english;
		double math;
		double sum;
	}student[n];
	
	StudentType tem;
	int mark;
	
	for(i=0;i<n;i++)
	{
		scanf("%s",&student[i].name);
	    scanf("%d",&student[i].sno);
	    scanf("%lf",&student[i].chinese);
	    scanf("%lf",&student[i].english);
	    scanf("%lf",&student[i].math);
	    student[i].sum=student[i].chinese+student[i].english+student[i].math;
	}
	while(n>0)
	{
	    for(i=0;i<n-1;i++)
        {
	    	
	   	    if(student[i].sum>student[i+1].sum)
	        {
	    	    tem=student[i];
	    	    student[i]=student[i+1];
	   	        student[i+1]=tem;
	        }
		    if(student[i].sum=student[i+1].sum)
		    {
			    if(stricmp(student[i].name,student[i+1].name)<0)
			    {
	    	        tem=student[i];
	    	        student[i]=student[i+1];
	   	            student[i+1]=tem;
	            }
		    }
		}
		printf("[name:%s,sum:%.0lf,sno:%d]\n",student[n-1].name,student[n-1].sum,student[n-1].sno);
		n-=1;
	}
        	
}
